package opera;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-07-14
 * Time: 14:25
 */
public class ReturnIOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书...");
        System.out.println("请输入你要归还的图书：");
        Scanner sc =  new Scanner(System.in);
        String name = sc.nextLine();

        int currentSize = bookList.getUseSized();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                if(book.isBorrowed() == false){
                    System.out.println("该图书未被借阅，不能归还");
                    return;
                }

                book.setBorrowed(false);
                System.out.println("归还成功");
            }
        }

    }

}
